import * as type from './type'
import {fromJS} from 'immutable'

const defaultState = fromJS({
    focus: false,
    list: [],
    MouseIn: false,
    page: 1,
    totalP: 1
})
// reducer可以接收state 不能修改state 纯函数
export default (state = defaultState, action) => {
    // switch  替换if 语句
    switch (action.type) {
        case type.FOCUS:
            return state.set('focus', !state.get('focus'))
        case 'swl':
            return state.set('list', action.data).set('totalP', action.totalP)
        case 'ss':
            return state.get('page') + 1 > state.get('totalP') ? state.set('page', 1) : state.set('page', state.get('page') + 1)
        case 'mouse':
            return state.set('MouseIn', !state.get('MouseIn'))
        default:
            return state
    }
}
